/*
 * Copyright (C) 2016  Nicola Spanti (RyDroid) <dev@nicola-spanti.info>
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 * 
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 */


#include "PlanetWars2dRT-core/specific/model/universes_hard_coded.h"
#include "PlanetWars2dRT-core/specific/model/universe_planets.h"
#include "PlanetWars2dRT-core/specific/model/players_info.h"
#include "PlanetWars2dRT-core/specific/model/planet_position.h"
#include "PlanetWars2dRT-core/specific/model/planet_size.h"


EXTERN_C_BEGIN


struct universe_t
get_universe_hard_coded_line_3_planets(bool* success)
{
  if(success != NULL)
    {
      *success = true;
    }
  
  struct universe_t a_universe;
  universe_init_first_time_only(&a_universe);
  a_universe.size.x = 450;
  a_universe.size.y = 450;
  
  struct planet_t a_planet;
  planet_init_first_time_only_default(&a_planet);
  planet_set_radius(&a_planet, 40);
  a_planet.nb_updates_before_next_production = 0;
  
  a_planet.player_index = 0;
  planet_set_top_left_position_x(&a_planet,  50);
  planet_set_top_left_position_y(&a_planet,  50);
  if(!universe_add_planet_unsafe(&a_universe, &a_planet) && success != NULL)
    {
      *success = false;
    }
  planet_set_top_left_position_x(&a_planet, 200);
  planet_set_top_left_position_y(&a_planet, 200);
  if(!universe_add_planet_unsafe(&a_universe, &a_planet) && success != NULL)
    {
      *success = false;
    }
  a_planet.player_index = 1;
  planet_set_top_left_position_x(&a_planet, 350);
  planet_set_top_left_position_y(&a_planet, 350);
  if(!universe_add_planet_unsafe(&a_universe, &a_planet) && success != NULL)
    {
      *success = false;
    }
  
  return a_universe;
}

struct universe_t
get_universe_hard_coded_line_4_planets(bool* success)
{
  struct universe_t a_universe;
  a_universe = get_universe_hard_coded_line_3_planets(success);
  
  a_universe.size.x = 600;
  a_universe.size.y = 600;
  
  struct planet_t a_planet;
  planet_init_first_time_only_default(&a_planet);
  planet_set_radius(&a_planet, 40);
  a_planet.nb_updates_before_next_production = 0;
  
  universe_get_planet_no_check(&a_universe, 2)->player_index = NULL_PLAYER_INDEX;
  
  a_planet.player_index = 1;
  planet_set_top_left_position_x(&a_planet, 500);
  planet_set_top_left_position_y(&a_planet, 500);
  if(!universe_add_planet_unsafe(&a_universe, &a_planet) && success != NULL)
    {
      *success = false;
    }
  
  return a_universe;
}

struct universe_t
get_universe_hard_coded_line_5_planets(bool* success)
{
  struct universe_t a_universe;
  a_universe = get_universe_hard_coded_line_4_planets(success);
  
  a_universe.size.x = 750;
  a_universe.size.y = 750;
  
  struct planet_t a_planet;
  planet_init_first_time_only_default(&a_planet);
  planet_set_radius(&a_planet, 40);
  a_planet.nb_updates_before_next_production = 0;
  
  universe_get_planet_no_check(&a_universe, 3)->player_index = NULL_PLAYER_INDEX;
  
  a_planet.player_index = 1;
  planet_set_top_left_position_x(&a_planet, 650);
  planet_set_top_left_position_y(&a_planet, 650);
  if(!universe_add_planet_unsafe(&a_universe, &a_planet) && success != NULL)
    {
      *success = false;
    }
  
  return a_universe;
}

struct universe_t
get_universe_hard_coded_triforce_small_6_planets(bool* success)
{
  if(success != NULL)
    {
      *success = true;
    }
  
  struct universe_t a_universe;
  universe_init_first_time_only(&a_universe);
  a_universe.size.x = 700;
  a_universe.size.y = 550;
  
  struct planet_t a_planet;
  planet_init_first_time_only_default(&a_planet);
  planet_set_radius(&a_planet, 40);
  a_planet.nb_updates_before_next_production = 0;
  
  planet_set_top_left_position_x(&a_planet,  20);
  planet_set_top_left_position_y(&a_planet,  20);
  a_planet.player_index = 0;
  if(!universe_add_planet(&a_universe, &a_planet) && success != NULL)
    {
      *success = false;
    }
  
  planet_set_top_left_position_x(&a_planet, 310);
  planet_set_top_left_position_y(&a_planet,  20);
  a_planet.player_index = NULL_PLAYER_INDEX;
  if(!universe_add_planet(&a_universe, &a_planet) && success != NULL)
    {
      *success = false;
    }
  
  planet_set_top_left_position_x(&a_planet, 600);
  planet_set_top_left_position_y(&a_planet,  20);
  a_planet.player_index = 1;
  if(!universe_add_planet(&a_universe, &a_planet) && success != NULL)
    {
      *success = false;
    }
  
  planet_set_top_left_position_x(&a_planet, 155);
  planet_set_top_left_position_y(&a_planet, 215);
  a_planet.player_index = NULL_PLAYER_INDEX;
  if(!universe_add_planet(&a_universe, &a_planet) && success != NULL)
    {
      *success = true;
    }
  
  planet_set_top_left_position_x(&a_planet, 465);
  planet_set_top_left_position_y(&a_planet, 215);
  a_planet.player_index = NULL_PLAYER_INDEX;
  if(!universe_add_planet(&a_universe, &a_planet) && success != NULL)
    {
      *success = false;
    }
  
  planet_set_top_left_position_x(&a_planet, 310);
  planet_set_top_left_position_y(&a_planet, 450);
  a_planet.player_index = 2;
  if(!universe_add_planet(&a_universe, &a_planet) && success != NULL)
    {
      *success = false;
    }
  
  return a_universe;
}

struct universe_t
get_universe_hard_coded_square_not_filled_small_8_planets(bool* success)
{
  if(success != NULL)
    {
      *success = true;
    }
  
  struct universe_t a_universe;
  universe_init_first_time_only(&a_universe);
  a_universe.size.x = 700;
  a_universe.size.y = 550;
  
  struct planet_t a_planet;
  planet_init_first_time_only_default(&a_planet);
  planet_set_radius(&a_planet, 40);
  a_planet.nb_updates_before_next_production = 0;
  
  planet_set_top_left_position_x(&a_planet,  20);
  planet_set_top_left_position_y(&a_planet,  20);
  a_planet.player_index = 0;
  if(!universe_add_planet(&a_universe, &a_planet) && success != NULL)
    {
      *success = false;
    }
  
  planet_set_top_left_position_x(&a_planet, 310);
  planet_set_top_left_position_y(&a_planet,  20);
  a_planet.player_index = NULL_PLAYER_INDEX;
  if(!universe_add_planet(&a_universe, &a_planet) && success != NULL)
    {
      *success = false;
    }
  
  planet_set_top_left_position_x(&a_planet, 600);
  planet_set_top_left_position_y(&a_planet,  20);
  a_planet.player_index = 1;
  if(!universe_add_planet(&a_universe, &a_planet) && success != NULL)
    {
      *success = false;
    }
  
  planet_set_top_left_position_x(&a_planet,  20);
  planet_set_top_left_position_y(&a_planet, 235);
  a_planet.player_index = NULL_PLAYER_INDEX;
  if(!universe_add_planet(&a_universe, &a_planet) && success != NULL)
    {
      *success = false;
    }
  
  planet_set_top_left_position_x(&a_planet, 600);
  planet_set_top_left_position_y(&a_planet, 235);
  a_planet.player_index = NULL_PLAYER_INDEX;
  if(!universe_add_planet(&a_universe, &a_planet) && success != NULL)
    {
      *success = false;
    }
  
  planet_set_top_left_position_x(&a_planet,  20);
  planet_set_top_left_position_y(&a_planet, 450);
  a_planet.player_index = 2;
  if(!universe_add_planet(&a_universe, &a_planet) && success != NULL)
    {
      *success = false;
    }
  
  planet_set_top_left_position_x(&a_planet, 310);
  planet_set_top_left_position_y(&a_planet, 450);
  a_planet.player_index = NULL_PLAYER_INDEX;
  if(!universe_add_planet(&a_universe, &a_planet) && success != NULL)
    {
      *success = false;
    }
  
  planet_set_top_left_position_x(&a_planet, 600);
  planet_set_top_left_position_y(&a_planet, 450);
  a_planet.player_index = 3;
  if(!universe_add_planet(&a_universe, &a_planet) && success != NULL)
    {
      *success = false;
    }
  
  return a_universe;
}

struct universe_t
get_universe_hard_coded_square_filled_small_9_planets(bool* success)
{
  struct universe_t a_universe;
  a_universe = get_universe_hard_coded_square_not_filled_small_8_planets(success);
  
  struct planet_t a_planet;
  planet_init_first_time_only_default(&a_planet);
  planet_set_radius(&a_planet, 40);
  a_planet.nb_updates_before_next_production = 0;
  
  planet_set_top_left_position_x(&a_planet, 310);
  planet_set_top_left_position_y(&a_planet, 235);
  a_planet.player_index = NULL_PLAYER_INDEX;
  if(!universe_add_planet(&a_universe, &a_planet) && success != NULL)
    {
      *success = false;
    }
  
  return a_universe;
}


EXTERN_C_END
